package week05;

import static org.junit.jupiter.api.Assertions.*;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = CampAutoConfigurationTestWithProfile.class)
@SpringBootApplication
@SpringJUnitConfig
@ActiveProfiles("test")
public class CampAutoConfigurationTestWithProfile {

    @Autowired
    ApplicationContext context;

    @Test
    public void testStarter() {
        CampService service = context.getBean("camp", CampService.class);
        assertEquals(service, context.getBean("camp"));
        assertEquals(service.getWeek(), 5);
        assertEquals(service.getDate(), "2021-07-23");

        assertThrows(NoSuchBeanDefinitionException.class, () -> context.getBean("camp_not_found", CampService.class));
    }
}
